In [8]:
import subprocess
import tempfile
import os
Np = 1000
def measure(N, fc, fs):
EXTRA = 250000
handle, path = tempfile.mkstemp()
os.close(handle)
args = ["uhd_rx_cfile", "-v",
"--freq=%d" % (fc,),
"--nsamples=%d" % (N + EXTRA,),
"--samp-rate=%f" % (fs,),
"-ATX/RX",
path]
subprocess.check_call(args)
x = fromfile(path, dtype=numpy.dtype(numpy.complex64))
os.unlink(path)
return real(x[EXTRA:])
In [9]:
def get_lambda(x, L=25):
x0 = x - mean(x)
Ns = len(x0)
lbd = empty(L)
for l in xrange(L):
if l > 0:
xu = x0[:-l]
else:
xu = x0
lbd[l] = dot(xu, x0[l:]) / (Ns - l)
return lbd
In [10]:
def plot_lambda(lbd, lbdcmp):
plot(lbd, 'o-', label="measured")
plot(lbdcmp, 'ko-', label="simulated")
ylabel("$\lambda_l$")
xlabel("$l$")
legend()
grid()
In [11]:
def measure_and_plot(N, fs):
x = measure(N=N, fs=fs, fc=864e6)
xcmp = random.normal(loc=mean(x), scale=std(x), size=len(x))
lbd = get_lambda(x, 25)
lbdcmp = get_lambda(xcmp, 25)
plot_lambda(lbd, lbdcmp)
title("$f_s=%d$ MHz" % (fs/1e6,))
In [82]:
measure_and_plot(N=25000*Np, fs=1e6)
savefig("figures/1mhz_noise_lambda.png", dpi=300)
In [83]:
measure_and_plot(N=25000*Np, fs=2e6)
savefig("figures/2mhz_noise_lambda.png", dpi=300)
In [84]:
measure_and_plot(N=100000*Np, fs=10e6)
savefig("figures/10mhz_noise_lambda.png", dpi=300)
In [79]:
measure_and_plot(N=25000*Np, fs=1e6)
savefig("figures/1mhz_noise_lambda_gen_30dbm.png", dpi=300)
In [80]:
measure_and_plot(N=25000*Np, fs=2e6)
savefig("figures/2mhz_noise_lambda_gen_30dbm.png", dpi=300)
In [81]:
measure_and_plot(N=100000*Np, fs=10e6)
savefig("figures/10mhz_noise_lambda_gen_30dbm.png", dpi=300)
In [4]:
sys.path.append("..")
import sensing.signals
In [5]:
Ns = 25000
fs=2e6
x1 = sensing.signals.SimulatedIEEEMicSoftSpeaker().get(N=Ns*Np, fc=864e6, fs=fs, Pgen=-200)
In [6]:
x2 = sensing.signals.Spurious(sensing.signals.SimulatedIEEEMicSoftSpeaker(), fs/128, -108).get(N=Ns*Np, fc=864e6, fs=fs, Pgen=-200)
In [7]:
plot(get_lambda(x1), 'o-')
plot(get_lambda(x2), 'o-')
title("$f_s=%d$ MHz" % (fs/1e6,))
grid()
In [8]:
x3 = sensing.signals.SimulatedIEEEMicSoftSpeaker().get(N=Ns*Np, fc=864e6, fs=fs, Pgen=-200)
#x3 = sensing.signals.Spurious(sensing.signals.SimulatedIEEEMicSoftSpeaker(), fs/32, -110).get(N=Ns*Np*2, fc=864e6, fs=fs, Pgen=-200)
In [23]:
def do_fft(x, k=1):
x0 = reshape(x, (Np/k, Ns))
w0 = fft.rfft(x0, axis=1)
w1 = mean(w0, axis=0)
return 10*log10(abs(w1**2))
plot(do_fft(x3, k=1))
Out[23]:
In [24]:
from scipy.signal import decimate
In [31]:
x3d = decimate(x3, 16)
#print len(x3d)
plot(do_fft(x3d, k=8))
In [28]:
print len(x3d)*16, len(x3)
In [40]:
plot(get_lambda(x3), 'ro-')
plot(get_lambda(x3d), 'go-')
title("$f_s=%d$ MHz" % (fs/1e6,))
grid()
In [9]:
x3 = sensing.signals.SimulatedIEEEMicSoftSpeaker().get(N=Ns*Np, fc=864e6, fs=fs, Pgen=-200)
In [70]:
import scipy.signal
b, a = scipy.signal.iirdesign(wp=.6, ws=.99, gpass=5, gstop=60, ftype='ellip')
y3 = scipy.signal.lfilter(b, a, x3)
print b, a
In [71]:
plot(do_fft(y3, k=1));
In [72]:
plot(get_lambda(y3), 'go-')
Out[72]:
In [14]:
x = measure(N=Np*25000, fs=2e6, fc=864e6)
In [15]:
plot(x)
Out[15]:
In [38]:
def do_fft(x):
x0 = reshape(x, (8000, 12500/4))
w0 = fft.rfft(x0, axis=1)
w1 = mean(w0, axis=0)
return 10.*log10(abs(w1**2))
plot(do_fft(x)[1:], '-')
axis([0, None, None, None])
Out[38]:
In [22]:
plot(get_lambda(x), 'o-')
Out[22]:
In [ ]: